package web;

import entity.Staffs;
import servlet.StaffsServlet;

import java.util.List;

public class StaffsTest {
    public static void main(String[] args) {

            query();
//            del();
            add();
            update();
            queryFy();
            queryId();
    }

    //查询
    public static void query() {
        //查询
        System.out.println("查询");
        List<Staffs> sta = StaffsServlet.query();
        for (Staffs s: sta) {
            System.out.println("编号："+s.getId());
            System.out.println("姓名："+s.getName());
            System.out.println("年龄："+s.getAge());
            System.out.println("联系方式："+s.getPhone());
            System.out.println("职位："+s.getPos());
            System.out.println("入职日期："+s.getAdd_time());
            System.out.println("更新时间："+s.getUpdate_time());
        }
    }

    //删除
    //删除的编号是第几行
    public static void del() {
        //删除
//        删除的编号是第几行
        System.out.println("删除");
        int result = StaffsServlet.del(2);
        System.out.println(result>0?"删除成功":"删除失败");
    }

    //添加
    public static void add() {
        //添加

        System.out.println("添加");
        Staffs sta = new Staffs();
        sta.setName("zl");
        sta.setAge(16);
        sta.setPhone("16779335176");
        sta.setPos("包工头");
        sta.setAdd_time("2022-01-03");
        sta.setUpdate_time("2024-03-06");
        int result = StaffsServlet.add(sta);
        System.out.println(result>0?"添加成功":"添加失败");
    }

    //修改
    //根据编号来修改姓名
    public static void update() {
        //修改
        //根据编号来修改姓名
        System.out.println("修改");
        Staffs sta = new Staffs();
        sta.setName("赵六");
        sta.setId(3);
        int result = StaffsServlet.update(sta);
        System.out.println(result>0?"修改成功":"修改失败");
    }

    //分页查询
    public static void queryFy() {
        //分页查询
        System.out.println("分页查询");
        List<Staffs> list = StaffsServlet.queryFy(5,5);
        for (Staffs s: list) {
            System.out.println("编号："+s.getId());
            System.out.println("姓名："+s.getName());
            System.out.println("年龄："+s.getAge());
            System.out.println("联系方式："+s.getPhone());
            System.out.println("职位："+s.getPos());
            System.out.println("入职日期："+s.getAdd_time());
            System.out.println("更新时间："+s.getUpdate_time());
        }
    }

    //根据id查询
    public static void queryId() {
        //根据id查询
        System.out.println("根据id查询");
        List<Staffs> list = StaffsServlet.queryId(1);
        for (Staffs s: list) {
            System.out.println("编号："+s.getId());
            System.out.println("姓名："+s.getName());
            System.out.println("年龄："+s.getAge());
            System.out.println("联系方式："+s.getPhone());
            System.out.println("职位："+s.getPos());
            System.out.println("入职日期："+s.getAdd_time());
            System.out.println("更新时间："+s.getUpdate_time());
        }
    }
}
